package com.xbongbong.formula.qlexpress.operator.text;

import com.ql.util.express.Operator;
import com.ql.util.express.OperatorOfNumber;
import com.xbongbong.formula.constant.Constant;

/**
 * @author: wufeng
 * @date: 2018/7/4 17:18
 * @desrcption: 返回正的平方根。
 */
public class OperatorSqrt extends Operator {



    public OperatorSqrt(String name){
        this.name = name;
    }

    public OperatorSqrt(String aliasName, String aName, String errorInfo){
        this.aliasName = aliasName;
        this.name = aName;
        this.errorInfo = errorInfo;
    }

    @Override
    public Object executeInner(Object[] list) throws Exception {
        int scale = Constant.SCALE;
        if(list.length == Constant.LENGTH){
            scale = ((Number) list[1]).intValue();
        }
       return executeInner(list[0], scale);
    }

    /**
     *
     * @author wufeng
     * @date 2018/7/10 15:04
     * @param object1 求平方根的数值
     * @param object2 需要保留的小数点位数
     * @return java.lang.Object
     */
    public Object executeInner(Object object1, Object object2) throws Exception{

        return OperatorOfNumber.round(Math.sqrt(((Number) object1).doubleValue()), ((Number) object2).intValue());
    }
}
